package com.system.service.impl;

import com.system.mapper.AddresslistCustomMapper;
import com.system.mapper.AddresslistMapper;
import com.system.mapper.CollegeMapper;
import com.system.po.*;
import com.system.service.AddresslistService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class AddresslistServiceImpl implements AddresslistService {

    @Resource
    private AddresslistMapper addresslistMapper;

    @Resource
    private AddresslistCustomMapper addresslistCustomMapper;

    @Resource
    private CollegeMapper collegeMapper;


    @Override
    public void upadteById(Integer id, AddresslistCustom addresslistCustom) throws Exception {

    }

    @Override
    public Boolean removeById(Integer id) throws Exception {
        return null;
    }

    @Override
    public List<AddresslistCustom> findByPaging(Integer toPageNo) throws Exception {
        PagingVO pagingVO=new PagingVO();
        pagingVO.setToPageNo(toPageNo);
        return addresslistCustomMapper.findByPaging(pagingVO);
    }

    @Override
    public Boolean save(AddresslistCustom addresslistCustom) throws Exception {
        return null;
    }

    @Override
    public int getCountCouse() throws Exception {
        return addresslistMapper.getCount();
    }

    @Override
    public AddresslistCustom findById(Integer id) throws Exception {
        return null;
    }

    @Override
    public List<AddresslistCustom> findByName(String name) throws Exception {
        List<AddresslistCustom> ans=new ArrayList<>();
        List<Addresslist> list = addresslistMapper.selectByName(name);
        if (list!=null){
            for (Addresslist ac : list) {
                AddresslistCustom addresslistCustom=new AddresslistCustom();
                //获取所属学院名
                College college = collegeMapper.selectByPrimaryKey(ac.getCollegeid());
                addresslistCustom.setAddressid(ac.getAddressid());
                addresslistCustom.setName(ac.getName());
                addresslistCustom.setTelephone(ac.getTelephone());
                addresslistCustom.setcollegeName(college.getCollegename());
                ans.add(addresslistCustom);
            }
        }
        return ans;
    }
}
